/*
 * DB.h
 *
 *  Created on: 2024年9月6日
 *      Author: nwz
 */

#ifndef CODE_DB_H_
#define CODE_DB_H_

class DB {
private:
	std::string name;
	sqlite3 *db;
	char buffer[COMMON_BUFFER_SIZE];

	void createTables();

public:
	DB(std::string dbname);
	virtual ~DB();

	int init();

	void getTbTbs(std::vector<struct table_tab> &tbs);
	void getTbMenus(std::vector<struct table_menu> &tbs);
	void getTbTbWins(std::vector<struct table_tab_win> &tbs);
	void getTbMenuCmds(std::vector<struct table_menu_cmd> &tbs);
	void getTbConfigInts(std::vector<struct table_config_int> &tbs);

	void deleteTbs();
	void deleteTbWins();
	void deleteMenus();
	void deleteMenuCmds();
	void insertTbs(std::vector<struct table_tab> &tbs);
	void insertTbWins(std::vector<struct table_tab_win> &tbs);
	void insertMenus(std::vector<struct table_menu> &tbs);
	void insertMenuCmds(std::vector<struct table_menu_cmd> &tbs);

	void updateWinRect(int x, int y, int width, int height);
	void updateAttachWinRect(int x, int y, int width, int height);

	void startCommit();
	void endCommit();
};

#endif /* CODE_DB_H_ */
